package jp.sourceforge.akjrcp.ui.param;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import jp.sourceforge.akjrcp.ui.param.AbstractParamCompositeItem.SelectionCheck;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class ParamBoolean extends AbstractParamCompositeItem{

private String key;
private String label;

private Button check;
private Label labelItem;

private String value="";

public Button getButton(){
	return check;
}
public String getKey() {
	return key;
}

public String getLabel() {
	return label;
}



public void setToolTipText(String text){
	labelItem.setToolTipText(text);
	this.check.setToolTipText(text);
}



public String getValue() {
	if(check.getSelection()){
		return "1";
	}else{
		return "";
	}
}

public boolean getBoolean() {
	return getValue().equals("1");
}

public void setBoolean(boolean bool){
	if(bool){
		setValue("1");
	}else{
		setValue("");
	}
}
public void setValue(String value) {
	if(!value.equals("")){
		check.setSelection(true);
	}else{
		check.setSelection(false);
	}
	this.value=value;
}
public ParamBoolean(Composite parent, int style,String key,String label) {
	this(parent,style,key,label,true);
}
	public ParamBoolean(Composite parent, int style,String key,String label,boolean labelFirst) {
		super(parent, style);
		
		this.key=key;
		this.label=label;
		
		this.setLayout(new GridLayout(2,false));
		if(labelFirst){
		labelItem = new Label(this,SWT.NONE);
		labelItem.setText(label);
		
		check = new Button(this,SWT.CHECK);
		check.addSelectionListener(new SelectionCheck());
		}else{
			check = new Button(this,SWT.CHECK);
			check.addSelectionListener(new SelectionCheck());
			
			labelItem = new Label(this,SWT.NONE);
			labelItem.setText(label);
		}
		GridData gdata=new GridData();
		//gdata.minimumWidth=20;
		gdata.grabExcessHorizontalSpace=false;
		//text.setLayoutData(gdata);
	}


	
	public boolean isModified() {
		
		String oldValue=getValue();
		
		
		
		return !oldValue.equals(value);
	}



}
